{include file="../app/common/admin/lib/header.html" title="自定义菜单"}
<div class="menubox" style="width:auto;">
  <div class="menu-top clearfix">
    <div class="btn-area right">
      <a href="javascript:void(0);" class="btn btn-success btn-sm js_saveSort">保存排序</a>
      <a href="{:url('/appmenu/admin/index')}" class="btn btn-default btn-sm">&lt;&nbsp;返回列表</a>
    </div>
    <span class="tit5">自定义菜单排序</span>
  </div>
  <dl class="alert" style="margin-top:20px;">
    <dt>特别提示：</dt>
    <dd>
      <p>拖动菜单进行排序</p>
      <p>编辑中的菜单不会马上被用户看到，可以放心调试。</p>
    </dd>
  </dl>
  <div class="menu-main clearfix">
    {foreach $menu_lenth_arr as $k=>$v}
    <div class="level {if $k == 2}nomr{/if}" data-view-order="{$k}" data-id="{$menu_list[$k].id}">
      {/*真实的菜单体*/}
      <div class="showmenu menuOuterBox">
        <dl class="menu-list">
          {/*父级*/}
          <dt class="clearfix js_parentMenu js_menuDD" data-id="{$menu_list[$k]['id']}" data-content-type="{$menu_list[$k]['type']}">
            {/*父级item*/}
            <div class="barfill clearfix js_menuItem" {if !isset($menu_list[$k])}style="display:none;"{/if}>
              <span class="menutit fs18 left">{$menu_list[$k]['title']}</span>
            </div>
          </dt>
          {/*子级*/}
          <div class="child-list">
          {foreach $menu_list[$k]['son_list'] as $k1=>$v1}
            <dd class="js_sonMenu js_menuDD" data-id="{$v1.id}" data-parent-id="{$v1.parent_id}" data-content-type="{$v1.type}">
              {/*子级item*/}
              <div class="submenu clearfix js_menuItem">
                <span class="menutit left">{$v1.title}</span>
              </div>
            </dd>
          {/foreach}
          </div>
        </dl>
      </div>
    </div>
    {/foreach}
  </div><!--end .menu-main-->
  <div class="ntcbox">
    <p><span class="dark-gray">提示：</span><span class="color"> 一级菜单</span>，横向拖动。<span class="color"> 二级菜单</span>，在该一级菜单内纵向拖动。</p>
    <p class="padl">拖动后如果想保存当前排序，请点击<span class="color"> 保存排序</span>；若不想保存，请点击<span class="color"> 取消返回列表</span>。</p>
  </div>
</div><!--end .menubox-->
<script>
var postData = { 'data_parent':{}, 'data_child':{} };
$(function(){
  $( ".menu-main" ).sortable({ 
    containment: "body" ,
    opacity: 0.6 , 
    cursorAt:{ top:60,left:70 },
    stop:saveParentSort
  });
  $( ".child-list" ).sortable({ 
    axis: "y" ,
    opacity: 0.6 , 
    stop:saveChildSort
  });
  /*
  $('.menu-list').sortable({ axis: 'y' });
  var axis = $('.menu-list').sortable('dd', 'axis');
  $('.menu-list').sortable('dd', 'axis', 'y');
  */
  $('.js_saveSort').click(function(){
    consoleLog(postData);
    $.post(siteUrl+'/appmenu/admin/save_sort', postData, function(json){
      if (json.info != 'ok') {
        showMsg(json.info);
        return;
      }
      //showMsg('保存成功', 1);
      window.location.href = siteUrl+'/appmenu/admin/index';
    }, 'json');
  });
});
function saveParentSort()
{
  $('.level').removeClass('nomr');
  $('.level').each(function(i){
    if (i == 2) {
      $(this).addClass('nomr');
    }
    $(this).attr('data-view-order', i);
    postData['data_parent'][$(this).attr('data-id')] = $(this).attr('data-view-order');
  });
}

function saveChildSort()
{
  $('.js_sonMenu').each(function(i){
      $(this).attr('data-view-order', i);
      postData['data_child'][$(this).attr('data-id')] = $(this).attr('data-view-order');
  });
}
</script>
{include file="../app/common/admin/lib/footer.html"}